{extend name="app/shop/view/base.html" /}
{block name="resources"}
{/block}

{block name="main"}
<table id="audit_list" lay-filter="audit_list"></table>

<!-- 操作 -->
<script type="text/html" id="operation">
    <div class="ns-table-btn">
    	{{#  if(d.status == 0){ }}
    		<a class="layui-btn" lay-event="cancel">撤回审核</a>
    	{{#  } }}
    	{{#  if(d.status == 1){ }}
    		<a class="layui-btn" lay-event="release">发布</a>
    	{{#  } }}
    	{{#  if(d.status == 2 || d.status == 3){ }}
    		<a class="layui-btn" lay-event="reason">查看原因</a>
    	{{#  } }}
	</div>
</script>
{/block}

{block name="script"}
<script type="text/javascript">
	layui.use([], function() {

		var table = new Table({
            elem: '#audit_list',
            url: ns.url("wxoplatform://shop/weapp/record"),
            cols: [
                [
	                {
	                    field: 'version',
	                    title: '版本号',
	                    unresize: 'false',
	                    width: '15%'
	                },
	                {
	                    field: 'status_name',
	                    title: '状态',
	                    unresize: 'false',
	                    width: '10%',
	                    align: 'center'
	                }, 
	                {
	                    title: '审核提交时间',
	                    unresize: 'false',
	                    width: '15%',
	                    align: 'center',
	                    templet: function(data){
	                    	return data.create_time ? ns.time_to_date(data.create_time) : '-'
	                    }
	                }, 
	                {
	                    title: '审核通过时间',
	                    unresize: 'false',
	                    width: '15%',
	                    align: 'center',
	                    templet: function(data){
	                    	return data.audit_time ? ns.time_to_date(data.audit_time) : '-'
	                    }
	                }, 
	                {
	                    title: '发布时间',
	                    unresize: 'false',
	                    width: '15%',
	                    align: 'center',
	                    templet: function(data){
	                    	return data.release_time ? ns.time_to_date(data.release_time) : '-'
	                    }
	                }, 
	                {
	                    title: '操作',
	                    toolbar: '#operation',
	                    unresize: 'false',
	                    width: '17%'
	                }
                ]
            ],
        });

		/**
		 * 监听工具栏操作
		 */
		table.tool(function(obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'cancel': // 撤销审核
					$.ajax({
				        type: "post",
				        url: "{:addon_url('wxoplatform://shop/weapp/undocodeaudit')}",
				        dataType: "JSON",
				        data: {
				        	id: data.id
				        },
				        success: function (res) {
				        	layer.msg(res.message);
							if (res.code >= 0) {
								table.reload({ page: { curr: 1 } });
							}
				        }
				    });
					break;
				case 'release':
					$.ajax({
				        type: "post",
				        url: "{:addon_url('wxoplatform://shop/weapp/release')}",
				        dataType: "JSON",
				        data: {
				        	id: data.id
				        },
				        success: function (res) {
				        	layer.msg(res.message);
							if (res.code >= 0) {
								table.reload({ page: { curr: 1 } });
							}
				        }
				    });
					break;
				case 'reason':
					layer.open({
					  	type: 1,
					  	title: false,
					  	skin: 'weapp-preview',
					  	closeBtn: 1, //不显示关闭按钮
					  	anim: 0,
					  	shadeClose: false,
					  	content: data.reason +'<span>更多原因请登录<a href="https://mp.weixin.qq.com/" target="_blank">https://mp.weixin.qq.com/</a>查看</span>'
					});
					break;
			}
		});
	})
</script>
{/block}